package com.mcintyret.site.validation.password;

/**
 * User: mcintyret2
 * Date: 12/04/2012
 */
public class PasswordValidationError {

    private final static String DEFAULT_ERROR_MSG = "Invalid password";

    private final Object[] args;
    private final String errorCode;

    public PasswordValidationError(PasswordValidationErrorCodes errorCodeEnum, Object... args) {
        if (args == null || errorCodeEnum.getExpectedArgs() != args.length) {
            throw new IllegalArgumentException("Expected " + errorCodeEnum.getExpectedArgs() + " arguments " +
                    "associated with " + errorCodeEnum + " but got " + args);
        }
        this.errorCode = errorCodeEnum.getErrorCode();
        this.args = args;
    }

    public PasswordValidationError(PasswordValidationErrorCodes errorCodeEnum) {
        this(errorCodeEnum, new Object[]{});
    }

    public Object[] args() {
        return args;
    }

    public String errorCode() {
        return errorCode;
    }

    public String defaultMessage() {
        return DEFAULT_ERROR_MSG;
    }

}
